/**
 * 
 */
package edu.rice.myxo.utils;

/**
 * @author frogy Represent the vector by (0,0) to (x,y)
 * 
 */
public class Vector2D {

	/**
	 * Initialize the vector, from (ox,oy) to (ex,ey)
	 * 
	 * @param ox
	 * @param oy
	 * @param ex
	 * @param ey
	 */
	public Vector2D(double ox, double oy, double ex, double ey) {
		x = ex - ox;
		y = ey - oy;
	}

	/**
	 * initialize the vector, from (0,0) to (ex,ey)
	 * 
	 * @param ex
	 * @param ey
	 */
	public Vector2D(double ex, double ey) {
		x = ex;
		y = ey;
	}

	public Vector2D add(Vector2D v) {
		Vector2D result = new Vector2D(x + v.getX(), y + v.getY());
		return result;
	}

	public Vector2D normalizeVector() {
		double abs = Math.sqrt(x * x + y * y);
		Vector2D result = new Vector2D(x / abs, y / abs);
		return result;
	}

	public double abs() {
		return Math.sqrt(x * x + y * y);
	}

	private double x;

	private double y;

	/**
	 * @return the x
	 */
	public double getX() {
		return x;
	}

	/**
	 * @param x
	 *            the x to set
	 */
	public void setX(double x) {
		this.x = x;
	}

	/**
	 * @return the y
	 */
	public double getY() {
		return y;
	}

	/**
	 * @param y
	 *            the y to set
	 */
	public void setY(double y) {
		this.y = y;
	}
}
